% n=2, I(0) and I(1) components


function [A, r, p, x]=simul2_2(T)

% I(0) component

w=randn;

for t=2:T,
    w(t)=0.6*w(t-1)+randn;
end


% I(1) component

u=randn(1,2);

for t=2:T,
    u(t)=u(t-1)+randn;
end



n=2;

Q=ort(2);
x=Q*[u;w];

pmax=6;
BIC=zeros(1,pmax);
    
for p=1:pmax,
    
    [phi_{p}, C_{p}]=reg(x,p);
    
    BIC(p)=log(det(C_{p}))+p*n^2*log(T)/T;
    
end

[mB, p]=min(BIC);

C=C_{p};
phi=phi_{p};


for i=1:n
    for j=1:n
        
        if i==j,
            coef=[1 -phi(i+(0:p-1)*n,j)'];
        else
            coef=[0 -phi(i+(0:p-1)*n,j)'];
        end
        A{j,i}=coef(end:-1:1);


    end
end

F=[phi';eye((p-1)*n) zeros((p-1)*n,n)];

r=eig(F);
    
    
    
